package types

type Common struct {
	// Status indicates if message kind is status check
	Status bool `json:"-"`

	// ResourceIds contains multiple resource ids
	// It must be not empty if Status flag is true
	ResourceIds []string `json:"resourceIds"`

	// RqUUID is unique id of function instance
	RqUUID string `json:"rqUuid"`
	// ResourceId is unique id of product instance
	ResourceId string `json:"resourceId"`

	Timestamp    int64   `json:"timestamp"`
	Version      Version `json:"version"`
	FunctionCode string  `json:"functionCode"`
	StageCode    string  `json:"stageCode"`
	Content      string  `json:"content,omitempty"`
}

// ResourceResponse is response to Status request
type ResourceResponse struct {
	Error     *StatusResponseError `json:"error,omitempty"`
	Resources []ResourceStatus     `json:"resources"`
}

// ResourceStatus contains info about resource status
type ResourceStatus struct {
	ResourceId           string `json:"resourceId"`
	ResourceStatus       string `json:"resourceStatus,omitempty"`
	ResourceStatusReason string `json:"resourceStatusReason,omitempty"`
	ResourceStatusCode   string `json:"resourceStatusCode,omitempty"`
}

// SSPPartnerMessage is common ssp message that writes by the self-service portal
type SSPPartnerMessage struct {

	// Tenant is tenant of the project
	Tenant string `json:"tenant"`

	// ProjectCode is code of the project connected to the product
	ProjectCode string `json:"projectCode"`

	Common
}

type Version struct {
	Major int `json:"major"`
	Minor int `json:"minor"`
	Patch int `json:"patch"`
	Build int `json:"build"`
}

type InstanceAttributes struct {
	ResourceID string `json:"resourceId"`
	Content    string `json:"content"`
}

type InstanceAttributesContent struct {
	Security InstanceAttributesSecurity `json:"security"`
}

type InstanceAttributesSecurity struct {
	Endpoints string `json:"endpoints"`
}

type SSPMessage struct {
	// StageStatus contains status of stage instance
	// Possible values: STARTED, IN_PROGRESS, ERROR,
	// NEED_INFO, PAUSE, COMPLETE
	StageStatus string `json:"stageStatus"`

	InstanceUUID   string `json:"instanceUuid"`
	FunctionStatus string `json:"functionStatus"`
	AWP            *AWP   `json:"awp,omitempty"`
	ResourceStatus string `json:"resourceStatus"`

	Common
}

type AWP struct {
	// Possible values: iframe, bundle, source
	AWPType string `json:"awpType"`

	Entrypoint Entrypoint `json:"entryPoint"`
}

type Entrypoint struct {
	Src string `json:"src,omitempty"`
	JS  string `json:"js,omitempty"`
	CSS string `json:"css,omitempty"`
}

type Error struct {
	RqUUID         string `json:"rqUuid"`
	ProjectCode    string `json:"projectCode"`
	StageStatus    string `json:"stageStatus"`
	FunctionStatus string `json:"functionStatus"`
	Content        string `json:"content"`
	Status         string `json:"status"`
}

type StatusResponseError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
}

type Step struct {
	Name    string
	Status  []string
	Error   bool
	Content map[string]string
}
